import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";

var _dec, _dec2, _class, _class2;

/**
 * Editor - 编辑数据表单
 * @since 2019-1-28
 * @version 0.0.1

 */
import React from 'react';
import { Form, Input, Col, Row, InputNumber, Select, Modal, Spin, Tooltip, Icon } from 'antd';
import { Bind } from 'lodash-decorators';
import Switch from 'components/Switch';
import TLEditor from 'components/TLEditor';
import intl from 'utils/intl';
import styles from "../index.less?modules";
var FormItem = Form.Item;
var Option = Select.Option;
var formLayout = {
  labelCol: {
    span: 8
  },
  wrapperCol: {
    span: 16
  }
};
var ColumnDrawer = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_React$PureComponent) {
  _inherits(ColumnDrawer, _React$PureComponent);

  var _super = _createSuper(ColumnDrawer);

  function ColumnDrawer() {
    _classCallCheck(this, ColumnDrawer);

    return _super.apply(this, arguments);
  }

  _createClass(ColumnDrawer, [{
    key: "handleOK",
    value: function handleOK() {
      var _this$props = this.props,
          form = _this$props.form,
          onOk = _this$props.onOk;
      form.validateFields(function (err, fieldsValue) {
        if (!err) {
          onOk(fieldsValue);
        }
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          _this$props2$form$get = _this$props2.form.getFieldDecorator,
          getFieldDecorator = _this$props2$form$get === void 0 ? function (e) {
        return e;
      } : _this$props2$form$get,
          _this$props2$initData = _this$props2.initData,
          initData = _this$props2$initData === void 0 ? {} : _this$props2$initData,
          _this$props2$columnTy = _this$props2.columnTypeCode,
          columnTypeCode = _this$props2$columnTy === void 0 ? [] : _this$props2$columnTy,
          title = _this$props2.title,
          modalVisible = _this$props2.modalVisible,
          loading = _this$props2.loading,
          onCancel = _this$props2.onCancel,
          _this$props2$initLoad = _this$props2.initLoading,
          initLoading = _this$props2$initLoad === void 0 ? false : _this$props2$initLoad,
          templateType = _this$props2.templateType;
      var dataSource = templateType === 'C' ? columnTypeCode : columnTypeCode.filter(function (item) {
        return item.tag !== 'client';
      });
      var minValue = initData.minValue,
          maxValue = initData.maxValue,
          validateSet = initData.validateSet,
          columnName = initData.columnName,
          columnType = initData.columnType,
          length = initData.length,
          columnIndex = initData.columnIndex,
          columnCode = initData.columnCode,
          formatMask = initData.formatMask,
          regularExpression = initData.regularExpression,
          sampleData = initData.sampleData,
          description = initData.description,
          _initData$changeDataF = initData.changeDataFlag,
          changeDataFlag = _initData$changeDataF === void 0 ? 1 : _initData$changeDataF,
          _initData$nullableFla = initData.nullableFlag,
          nullableFlag = _initData$nullableFla === void 0 ? 1 : _initData$nullableFla,
          _initData$validateFla = initData.validateFlag,
          validateFlag = _initData$validateFla === void 0 ? 1 : _initData$validateFla,
          _initData$enabledFlag = initData.enabledFlag,
          enabledFlag = _initData$enabledFlag === void 0 ? 1 : _initData$enabledFlag,
          _token = initData._token;
      return /*#__PURE__*/React.createElement(Modal, {
        destroyOnClose: true,
        wrapClassName: "ant-modal-sidebar-right",
        transitionName: "move-right",
        title: title,
        width: 820,
        visible: modalVisible,
        confirmLoading: loading,
        onCancel: onCancel,
        onOk: this.handleOK
      }, /*#__PURE__*/React.createElement(Spin, {
        spinning: initLoading
      }, /*#__PURE__*/React.createElement(Form, {
        className: styles['template-column-input']
      }, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: /*#__PURE__*/React.createElement("span", null, intl.get("cimp.template.model.template.columnIndex").d('列号'), "\xA0", /*#__PURE__*/React.createElement(Tooltip, {
          title: intl.get('cimp.template.view.message.title.columnIndex').d('列号从0开始递增')
        }, /*#__PURE__*/React.createElement(Icon, {
          type: "question-circle-o"
        })))
      }, formLayout), getFieldDecorator('columnIndex', {
        initialValue: columnIndex,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get("cimp.template.model.template.columnIndex").d('列号')
          })
        }]
      })( /*#__PURE__*/React.createElement(InputNumber, {
        min: 0,
        style: {
          width: '100%'
        }
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.columnCode").d('列编码')
      }, formLayout), getFieldDecorator('columnCode', {
        initialValue: columnCode,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get("cimp.template.model.template.columnCode").d('列编码')
          })
        }, {
          pattern: /^[a-zA-Z0-9][a-zA-Z0-9-_./:]*$/,
          message: intl.get('cimp.template.model.template.columnCodePattern').d('大小写及数字，必须以字母、数字开头，可包含“-”、“_”、“.”、“/”、“:”')
        }]
      })( /*#__PURE__*/React.createElement(Input, {
        trim: true,
        inputChinese: false
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.columnName").d('列名')
      }, formLayout), getFieldDecorator('columnName', {
        initialValue: columnName,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get("cimp.template.model.template.columnName").d('列名')
          })
        }]
      })( /*#__PURE__*/React.createElement(TLEditor, {
        label: intl.get('cimp.template.model.template.columnName').d('列名'),
        field: "columnName",
        token: _token
      }))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.columnType").d('列类型')
      }, formLayout), getFieldDecorator('columnType', {
        initialValue: columnType,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validation.notNull', {
            name: intl.get("cimp.template.model.template.columnType").d('列类型')
          })
        }]
      })( /*#__PURE__*/React.createElement(Select, null, dataSource.map(function (n) {
        return /*#__PURE__*/React.createElement(Option, {
          key: n.value,
          value: n.value
        }, n.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.formatMask").d('格式掩码')
      }, formLayout), getFieldDecorator('formatMask', {
        initialValue: formatMask
      })( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.length").d('长度')
      }, formLayout), getFieldDecorator('length', {
        initialValue: length
      })( /*#__PURE__*/React.createElement(InputNumber, {
        min: 0,
        style: {
          width: '100%'
        }
      }))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.minValue").d('最小值')
      }, formLayout), getFieldDecorator('minValue', {
        initialValue: minValue
      })( /*#__PURE__*/React.createElement(InputNumber, {
        min: 0,
        style: {
          width: '100%'
        }
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.maxValue").d('最大值')
      }, formLayout), getFieldDecorator('maxValue', {
        initialValue: maxValue
      })( /*#__PURE__*/React.createElement(InputNumber, {
        min: 0,
        style: {
          width: '100%'
        }
      })))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.validateSet").d('验证值集')
      }, formLayout), getFieldDecorator('validateSet', {
        initialValue: validateSet
      })( /*#__PURE__*/React.createElement(Input, null))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.regularExpression").d('正则式')
      }, formLayout), getFieldDecorator('regularExpression', {
        initialValue: regularExpression
      })( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.sampleData").d('示例数据')
      }, formLayout), getFieldDecorator('sampleData', {
        initialValue: sampleData
      })( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.description").d('描述')
      }, formLayout), getFieldDecorator('description', {
        initialValue: description
      })( /*#__PURE__*/React.createElement(Input, null))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cpaas.common.status.enable").d('启用')
      }, formLayout), getFieldDecorator('enabledFlag', {
        initialValue: enabledFlag
      })( /*#__PURE__*/React.createElement(Switch, null)))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.nullable").d('允许为空')
      }, formLayout), getFieldDecorator('nullableFlag', {
        initialValue: nullableFlag
      })( /*#__PURE__*/React.createElement(Switch, null)))), /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.validate").d('数据验证')
      }, formLayout), getFieldDecorator('validateFlag', {
        initialValue: validateFlag
      })( /*#__PURE__*/React.createElement(Switch, null))))), /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Col, {
        span: 8
      }, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get("cimp.template.model.template.changeDataFlag").d('值集转换')
      }, formLayout), getFieldDecorator('changeDataFlag', {
        initialValue: changeDataFlag
      })( /*#__PURE__*/React.createElement(Switch, null))))))));
    }
  }]);

  return ColumnDrawer;
}(React.PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "handleOK", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "handleOK"), _class2.prototype)), _class2)) || _class);
export { ColumnDrawer as default };